package com.sgb.kjwl.view.ui.adapter.self.pick;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfPickListEntity3;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class SelfCollectAdapter extends BaseRecycleAdapter<SelfPickListEntity3> {
    private LinearLayout delLayout;
    private LinearLayout endTimeLayout;
    private TextView tvGroupBuyType;
    private ImageView stateImg;
    private ItemCallBack itemCallBack;
    //需方集采--停止集采
    private LinearLayout llXffq;
    private TextView tvStop;
    //我的加盟-- 退出和修改
    private LinearLayout llWdjm;
    private TextView tvExit;
    private TextView tvReedit;
    //1.我的集采   2.我的加盟
    private String type;

    public SelfCollectAdapter(Context context, List<SelfPickListEntity3> datas) {
        super(context, R.layout.item_self_collect, datas);
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfPickListEntity3 entity) {
        holder.setBinding(BR.viewModel, entity);
        delLayout = holder.getItem().findViewById(R.id.del_layout);
        endTimeLayout = holder.getItem().findViewById(R.id.end_time_layout);
        tvGroupBuyType = holder.getItem().findViewById(R.id.tv_group_buy_type);
        stateImg = holder.getItem().findViewById(R.id.state_img);
        llXffq = holder.getItem().findViewById(R.id.ll_xffq);
        tvStop = holder.getItem().findViewById(R.id.tv_stop);
        llWdjm = holder.getItem().findViewById(R.id.ll_wdjm);
        tvExit = holder.getItem().findViewById(R.id.tv_exit);
        tvReedit = holder.getItem().findViewById(R.id.tv_reedit);

        if (type.equals("1")) {//1.需方发起
            if (1 == entity.getGroupBuyType() || 3 == entity.getGroupBuyType()) {//即报集采  或者  企业专项
                if (entity.getStatus().equals("1")) {//进行中
                    llXffq.setVisibility(View.VISIBLE);
                } else {
                    llXffq.setVisibility(View.GONE);
                }
            } else if (2 == entity.getGroupBuyType()) {//汇集采购
                if (entity.getStatus().equals("5") || entity.getStatus().equals("6")) {//加盟中、报价中
                    llXffq.setVisibility(View.VISIBLE);
                } else {
                    llXffq.setVisibility(View.GONE);
                }
            }
        } else if (type.equals("2")) {//2.我的加盟
            if ("1".equals(entity.getStatus()) || "5".equals(entity.getStatus())) { // 1.集采中 5.加盟中
                llWdjm.setVisibility(View.VISIBLE);
            } else {
                llWdjm.setVisibility(View.GONE);
            }
        }

        switch (entity.getGroupBuyType()) {//1即报集采  2汇总集采  3企业专项
            case 1:
                tvGroupBuyType.setBackgroundResource(R.mipmap.jbjc);
                tvGroupBuyType.setText(R.string.jbjc);
                break;
            case 2:
                tvGroupBuyType.setBackgroundResource(R.mipmap.hzcg);
                tvGroupBuyType.setText(R.string.hzcg);
                break;
            case 3:
                tvGroupBuyType.setBackgroundResource(R.mipmap.qyzx);
                tvGroupBuyType.setText(R.string.qyzx);
                break;
        }
        switch (entity.getStatus()) {//状态  1 进行中2 已完成  3集采作废   4集采失败  5 加盟中 6 报价中
            case "1":
                stateImg.setImageResource(R.mipmap.collect_ing);
                break;
            case "2":
                stateImg.setImageResource(R.mipmap.collect_complate);
                break;
            case "3":
                stateImg.setImageResource(R.mipmap.jc_jczf);
                break;
            case "4":
                stateImg.setImageResource(R.drawable.collect_fail);
                break;
            case "5":
                stateImg.setImageResource(R.mipmap.jc_to_join);
                break;
            case "6":
                stateImg.setImageResource(R.mipmap.jc_bjz);
                break;
        }

        //需方发起--停止集采
        tvStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.stop(entity.getNo());
                }
            }
        });
        //我的加盟--退出加盟
        tvExit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != itemCallBack) {
                    itemCallBack.exit(entity.getNo());
                }
            }
        });
        //我的加盟--修改加盟
        tvReedit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != itemCallBack) {
                    itemCallBack.reedit(entity.getNo());
                }
            }
        });
    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;

    }

    public interface ItemCallBack {
        void stop(String id);

        void exit(String id);

        void reedit(String id);
    }
}
